﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using Grain.Crm.DataMigrator.CrmServices;

namespace Grain.Crm.DataMigrator.Infrastructure
{
    public class ValueAppender : IBuildable
    {
        public string DisplayName { get; set; }
        public ValueResolver Value { get; set; }

        [XmlIgnore]
        public string HeaderRow { get; set; }
        [XmlIgnore]
        public string ContentRow { get; set; }
        [XmlIgnore]
        public ICrmService Service { get; set; }

        protected ValueAppender()
        {
            Value = new ConstantValueResolver(null);
        }

        public ValueAppender(string displayName, ValueResolver valueResolver)
        {
            DisplayName = displayName;
            Value = valueResolver;
        }

        public void Build(Builder builder)
        {
            builder.Build(this);
            Value.Build(builder);
        }

        public KeyValuePair<string, string> Append(string headerRow, string contentRow)
        {
            headerRow += "," + DisplayName;
            contentRow += "," + Value.Resolve();

            return new KeyValuePair<string, string>(headerRow, contentRow);
        }
    }
}
